package StackAndQueuePackage;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @author Lzm
 * @version 1.0
 */
public class MyStack {
  Queue<Integer> queue;
  public MyStack() {
    queue = new LinkedList<>();
  }

  public void push(int x) {
    queue.add(x);
  }

  public int pop() {
    for (int i = 0 ; i < queue.size() - 1 ; i++){
      queue.add(queue.poll());
    }
    return queue.poll();
  }

  public int top() {
    for (int i = 0 ; i < queue.size() - 1 ; i++){
      queue.add(queue.poll());
    }
    return queue.peek();
  }

  public boolean empty() {
    return queue.isEmpty();
  }
}
